package com.ahsjdy.st.stbocustomer.controller;

import com.ahsjdy.st.stdao.entity.User;
import com.ahsjdy.stcommon.dto.ResponseDTO;
import com.ahsjdy.stcommon.exception.BizException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public abstract class BaseController {

    protected static final Logger logger = LoggerFactory.getLogger(BaseController.class);

    protected static final int max_day_send_msg_number = 10;
    protected static final int max_code_ip_count = 100;


    @Autowired
    protected HttpServletRequest request;

    @Autowired
    protected HttpSession session;

    @Value("${app.merchant.pic.path}")
    protected String picturePath;

    @Value("${app.merchant.pic.url}")
    protected String pictureUrl;


    protected int getUserId() {
        return 1000;
    }

    protected String getUsername() {
        return "admin";
    }

    protected User getUser() {
        return null;
    }

    @ExceptionHandler(BizException.class)
    protected ResponseDTO processBizException(BizException be) {
        logger.error(be.getMessage(), be);
        return ResponseDTO.failed(be.getMessage());
    }

    @ExceptionHandler(Exception.class)
    protected ResponseDTO processException(Exception e) {
        logger.error(e.getMessage(), e);
        return ResponseDTO.failed("系统出错，请联系管理员");
    }


}
